const Router = require("koa-router");
const jwt = require("jsonwebtoken");
const { secretKey } = require("../config");

const router = new Router({
  prefix: "/news",
});

router.get("/list", async (ctx) => {
    let data = {
        token: ctx.state.user,
        list: [{am:1},{am:2},{am:3}]
    }

    await ctx.render("list",data);
});

router.get("/login", async (ctx) => {
  let { uname, pwd } = ctx.request.body;

  var token = jwt.sign({ uname: uname }, secretKey, {
    algorithm: "HS256",
    expiresIn: "10h",
  });
  await ctx.render("login");
  // ctx.body={
  //     msg:"good",
  //     token:"Bearer " + token
  // }
});

module.exports = router;
